package com.ustc.py.learn.controller;


import com.ustc.py.learn.constant.KnowledgeTypeEnum;
import com.ustc.py.learn.entity.Knowledge;
import com.ustc.py.learn.entity.KnowledgeVo;
import com.ustc.py.learn.service.KnowledgeService;
import com.ustc.py.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 专门用于numpy模块学习 业务
 * Jackiehan is in charge.
 */
@RequestMapping("/learn/numpy")
@RestController
public class LearnNumpyController {
    @Autowired
    private KnowledgeService knowledgeService;

    /**
     * 获取Numpy知识列表集合
     * @return
     */
    @GetMapping("list")
    public R getNumpyList(){
        // 调用hui 接口
        List<KnowledgeVo> knowledgeMenuList = knowledgeService.getKnowledgeMenuList(KnowledgeTypeEnum.NUMPY.getTypeId());
        return R.jsonify(200, "OK", knowledgeMenuList);
    }

    /**
     * 根据ID获取具体某条Numpy知识详情
     * @param id 路径参数
     * @return
     */
    @GetMapping("{id}")
    public R getNumpyById(@PathVariable("id") Integer id){
        Knowledge knowledge = knowledgeService.getKnowledgeById(id);
        return R.jsonify(200, "0K", knowledge);
    }

    /**
     * 根据关键词模糊搜索Numpy知识
     * @param keyword param参数
     * @return
     */
    @GetMapping("search")
    public R searchNumpy(String keyword){
        List<KnowledgeVo> list = knowledgeService.search(KnowledgeTypeEnum.NUMPY.getTypeId(), keyword);
        return R.jsonify(200, "OK", list);
    }



}
